package com.superatom.concurrent.share;

public class SynchronizedEvenGenerator extends IntGenerator {
    private int currentEvenValue = 0;

    // synchronized关键字，每次只有一条任务进入该方法
    public synchronized int next() {
        ++currentEvenValue;
        Thread.yield();
        ++currentEvenValue;
        return currentEvenValue;
    }

    public static void main(String[] args) {
        EvenChecker.test(new SynchronizedEvenGenerator());
    }
}
